package cn.bytecollege.admin.controller;

import cn.bytecollege.admin.service.OrderService;
import cn.bytecollege.common.entity.Orders;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author NJK
 */
@WebServlet(name = "OrderCheckController",value = "/admin/orderCheck")
public class OrderCheckController extends HttpServlet {
    private OrderService orderService = null;
    public OrderCheckController(){
        orderService = new OrderService();
    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取订单Id
        String id = req.getParameter("id");
        //封装数据
        Orders orders = new Orders();
        orders.setOrderId(Integer.valueOf(id));
        //更改支付标志位
        orderService.updatePayFlag(orders);
        //获取订单总价用于计算营业额
        String tempTotalPrice = req.getParameter("totalPrice");
        Double totalPrice = Double.valueOf(tempTotalPrice);
        req.setAttribute("totalPrice",totalPrice);
        req.getRequestDispatcher(req.getContextPath()+"/admin/adminTurnover").forward(req,resp);
    }
}
